/* Chymera is the Sakura OSC transpondor and Conductor */
// simulator flowerstate = 32768

import controlP5.*;
import java.net.InetAddress;
ControlP5 cp5;

boolean androidMode;
boolean monitorMode;
String myIP, ipPrefix;
String padIP = "7";
int windowI=1;

InetAddress inet;



void setup() {
  size(300, 300);
  textSize(12);

  try {
    inet = InetAddress.getLocalHost();
    myIP = inet.getHostAddress();
    String buffer[]=split(myIP, ".");
    ipPrefix=buffer[0]+"."+buffer[1]+"."+buffer[2]+".";
  }
  catch (Exception e) {
    e.printStackTrace();
    myIP = "couldnt get IP";
  }
  commonSetup();
  InitPad();

  noStroke();
  cp5 = new ControlP5(this);
  // change the trigger event, by default it is PRESSED.
  cp5.addBang("bang")
    .setPosition(50, 150)
      .setSize(200, 50)
        .setTriggerEvent(Bang.RELEASE)
          .setLabel("Launch 1")
            ;
}

void draw() {
  background(0);
  if (keyCommand) {
    text(myIP+": Control IP", 25, 50);
    text(padIP+": Echo suffix", 25, 70);
    text("a) set echo suffix", 25, 265);
  }
  else {
    text("~ for key command", 24, 265);
  }
}
void bang() {
  int xLoc = (1920*2/8) * 7 + (1920*2/8-width)/2;
  int yLoc = (1920*2/8) + (1920*2/8-width)/2;
  windowI++;
  File baty = new File ("c:/AndroidDev/ChymeraRoot/chymera/application.windows64/chymera.bat");
  open("rundll32 SHELL32.DLL,ShellExec_RunDLL " + baty );
  String newLabel = "Launch "+windowI;
  cp5.getController("bang").setCaptionLabel(newLabel);
  //  frame.setLocation(xLoc, yLoc);
}
public void controlEvent(ControlEvent theEvent) {

  println(
  "## controlEvent / id:"+theEvent.controller().id()+
    " / name:"+theEvent.controller().name()+
    " / label:"+theEvent.controller().label()+
    " / value:"+theEvent.controller().value()
    );
}

